.TH std::raw_storage_iterator 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::raw_storage_iterator \- std::raw_storage_iterator

.SH Synopsis
   Defined in header <memory>
   template< class OutputIt, class T >

   class raw_storage_iterator                                     \fI(until C++17)\fP

       : public std::iterator<std::output_iterator_tag, void,
   void, void, void>;
   template< class OutputIt, class T >                            \fI(since C++17)\fP
   class raw_storage_iterator;                                    (deprecated in C++17)
                                                                  (removed in C++20)

   The output iterator std::raw_storage_iterator makes it possible for standard
   algorithms to store results in uninitialized memory. Whenever the algorithm writes
   an object of type T to the dereferenced iterator, the object is copy-constructed
   into the location in the uninitialized storage pointed to by the iterator. The
   template parameter OutputIt is any type that meets the requirements of
   LegacyOutputIterator and has operator* defined to return an object, for which
   operator& returns an object of type T*. Usually, the type T* is used as OutputIt.

.SH Type requirements

   -
   OutputIt must meet the requirements of LegacyOutputIterator.

.SH Member functions

   constructor     creates a new raw_storage_iterator
                   \fI(public member function)\fP
   operator=       constructs an object at the pointed-to location in the buffer
                   \fI(public member function)\fP
   operator*       dereferences the iterator
                   \fI(public member function)\fP
   operator++      advances the iterator
   operator++(int) \fI(public member function)\fP
   base            provides access to the wrapped iterator
   \fI(since C++17)\fP   \fI(public member function)\fP

.SH Member types

   Member type       Definition
   iterator_category std::output_iterator_tag
   value_type        void
   difference_type   void           \fI(until C++20)\fP
                     std::ptrdiff_t \fI(since C++20)\fP
   pointer           void
   reference         void

   Member types iterator_category, value_type, difference_type, pointer
   and reference are required to be obtained by inheriting from           \fI(until C++17)\fP
   std::iterator<std::output_iterator_tag, void, void, void, void>.

.SH Note

   std::raw_storage_iterator was deprecated primarily because of its exception-unsafe
   behavior. Unlike std::uninitialized_copy, it doesn't handle exceptions during
   operations like std::copy safely, potentially leading to resource leaks due to a
   lack of tracking the number of successfully constructed objects and their proper
   destruction in the presence of exceptions.

.SH Example


// Run this code

 #include <algorithm>
 #include <iostream>
 #include <memory>
 #include <string>

 int main()
 {
     const std::string s[] = {"This", "is", "a", "test", "."};
     std::string* p = std::allocator<std::string>().allocate(5);

     std::copy(std::begin(s), std::end(s),
               std::raw_storage_iterator<std::string*, std::string>(p));

     for (std::string* i = p; i != p + 5; ++i)
     {
         std::cout << *i << '\\n';
         i->~basic_string<char>();
     }
     std::allocator<std::string>().deallocate(p, 5);
 }

.SH Output:

 This
 is
 a
 test
 .

.SH See also

   allocator_traits         provides information about allocator types
   \fI(C++11)\fP                  \fI(class template)\fP
   scoped_allocator_adaptor implements multi-level allocator for multi-level containers
   \fI(C++11)\fP                  \fI(class template)\fP
   uses_allocator           checks if the specified type supports uses-allocator
   \fI(C++11)\fP                  construction
                            \fI(class template)\fP
